<?php
/* 
	This file is Copyright Matthew Wilkinson 2009.
	
	This file is part of Oxygen.

	Oxygen is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License version 3 as published by
	the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html

	Oxygen is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

*/

	Final Class Events
		{
		
		private static $events = Array();
		
		const POST_RENDER = 0;
		const USER_RENDER = 1;
		const TOPIC_RENDER = 2;
		const FORUM_RENDER = 3;
		const POST_INTERIM = 4;
		const TOPIC_INTERIM = 5;
		const FORUM_INTERIM = 6;
		const HTML_HEAD_RENDER = 7;
		
		
		const POST_CHANGE = 10;
		const USER_CHANGE = 11;
		const TOPIC_CHANGE = 12;
		const FORUM_CHANGE = 13;
		
		
		const POST_CREATE = 20;
		const USER_CREATE = 21;
		const TOPIC_CREATE = 22;
		const FORUM_CREATE = 23;
		
		
		public static function register($event, $callback)
			{
			$events[$event][] = $callback;
			}
		
		
		public static function announce($event, &$object)
			{
			$callevent = FALSE;
			if ($event < 10 AND Security::Caller() == 'Output')
				{
				$callevent = TRUE;
				}
			elseif ($event == Events::POST_CHANGE AND Security::Caller() == ' Post')
				{
				$callevent = TRUE;
				}
			elseif ($event == Events::USER_CHANGE AND Security::Caller() == 'User')
				{
				$callevent = TRUE;
				}
			elseif ($event == Events::TOPIC_CHANGE AND Security::Caller() == 'Topic')
				{
				$callevent = TRUE;
				}
			elseif ($event == Events::FORUM_CHANGE AND Security::Caller() == 'Forum')
				{
				$callevent = TRUE;
				}
			
			if ($callevent)
				{
				foreach (self::$events[$event] as $callback)
					{
					$object::$enable_events = FALSE;
					$callback(&$object);
					}
				$object::$enable_events = TRUE;
				}
			}
		
		}